package userInterface;

import javax.microedition.lcdui.*;
import javax.microedition.midlet.MIDlet;

public class ItemStuff 
	extends MIDlet
	implements CommandListener,
		ItemCommandListener,
		ItemStateListener
{
	private Form mForm;
	private Command mExitCommand, mClearCommand;
	private Gauge mGauge;
	private StringItem mStatus;
	
	protected void startApp(){
		if (mForm == null) {
			mForm = new Form("ItemStuff");
			// add the Exit and Clear commands
			mExitCommand = new Command("Exit", Command.EXIT, 0);
			mForm.addCommand(mExitCommand);
			mClearCommand = new Command("Clear", Command.SCREEN, 0);
			// add the Gauge
			mGauge = new Gauge("Change me!", true, 10, 0);
			mForm.append(mGauge);
			// add the StringItem, set it's command listener
			mStatus = new StringItem("Value: ", "");
			mStatus.setItemCommandListener(this);
			mStatus.addCommand(mClearCommand);
			mForm.append(mStatus);
			mForm.setCommandListener(this);
			mForm.setItemStateListener(this);
		}
		Display.getDisplay(this).setCurrent(mForm);
	}	
	protected void destroyApp(boolean arg0) {}
	protected void pauseApp() {}
	public void commandAction(Command c, Displayable d) {
		if (c == mExitCommand) {
			destroyApp(true);
			notifyDestroyed();
		}
	}
	public void commandAction(Command c, Item i) {
		if (c == mClearCommand && i == mStatus) {
			mStatus.setText("");
		}
		
	}
	public void itemStateChanged(Item i) {
		if (i == mGauge) {
			mStatus.setText("gauge=" + mGauge.getValue());
		}
	}
}
